package middleware

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
	"uniquen.top/golang-demo/response"
)

// RecoveryMiddleware 拦截error,通过panic拦截
func RecoveryMiddleware() gin.HandlerFunc {
	return func(ctx *gin.Context) {
		defer func() {
			if err := recover(); err != nil {
				response.Fail(ctx, http.StatusInternalServerError, 500, nil, fmt.Sprint(err))
			}
		}()

		ctx.Next()
	}
}
